# The American Viewer: Political Consequences of Entertainment Media
# Eunji Kim and Shawn Patterson Jr 
# American Political Science Review 
# Replication File [Appendix B Figure B1]

pollgraph <- read_csv("appendix_figureb1.csv")

pd <- position_dodge(0.2)

trendlineGraph <- ggplot(pollgraph, aes(x=FullDate, y=FavRating)) + 
  geom_rect(aes(xmin=as.Date("2004-01-08"), xmax=as.Date("2004-04-15"), ymin=0, ymax=0.7, fill="red1"), alpha=0.002, color=NA) +
  geom_text(aes(x=as.Date("2004-02-25"), y=0.1, label="Season 1 | 28.1 million"), size=3, angle=90) + 
  geom_rect(aes(xmin=as.Date("2004-09-08"), xmax=as.Date("2004-12-16"), ymin=0, ymax=0.7, fill="red1"), alpha=0.002, color=NA) +
  geom_text(aes(x=as.Date("2004-10-27"), y=0.1, label="Season 2 | 16.9 million"), size=3, angle=90) + 
  geom_rect(aes(xmin=as.Date("2005-01-20"), xmax=as.Date("2005-05-19"), ymin=0, ymax=0.7, fill="red1"), alpha=0.002, color=NA) +
  geom_text(aes(x=as.Date("2005-03-20"), y=0.1, label="Season 3 | 14.0 million"), size=3, angle=90) + 
geom_point(col="red4", na.rm=TRUE) + 
  labs(y="Favorability Rating", x=NA) + 
  scale_x_date(limits=c(as.Date("1999-06-01"), as.Date("2000-01-31")), date_breaks = "1 month", date_labels = "%b-%y", expand = c(0,0)) + 
  scale_y_continuous(limits=c(0,0.6), breaks=seq(0.0, 0.7, 0.1), expand = c(0,0)) + 
  geom_errorbar(aes(ymin=LowerCI, ymax=UpperCI), width=.1, position=pd, na.rm=TRUE) + 
  theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 5, color="black", face="bold"), legend.position = "none",
        panel.background = element_blank(), panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(), axis.title.x=element_blank())

trendlineGraph2 <- ggplot(pollgraph, aes(x=FullDate, y=FavRating)) + 
  geom_rect(aes(xmin=as.Date("2004-01-08"), xmax=as.Date("2004-04-15"), ymin=0, ymax=0.6, fill="grey70"), alpha=0.002, color=NA) +
  geom_text(aes(x=as.Date("2004-02-25"), y=0.1, label="Season 1 | 28.1 million"), size=3, angle=90) + 
  geom_rect(aes(xmin=as.Date("2004-09-08"), xmax=as.Date("2004-12-16"), ymin=0, ymax=0.6, fill="grey70"), alpha=0.002, color=NA) +
  geom_text(aes(x=as.Date("2004-10-27"), y=0.1, label="Season 2 | 16.9 million"), size=3, angle=90) + 
  geom_rect(aes(xmin=as.Date("2005-01-20"), xmax=as.Date("2005-05-19"), ymin=0, ymax=0.6, fill="grey70"), alpha=0.002, color=NA) +
  geom_text(aes(x=as.Date("2005-03-20"), y=0.1, label="Season 3 | 14.0 million"), size=3, angle=90) + 
geom_point(col="red4", na.rm=TRUE) + 
  #labs(y="Favorability Rating", x=NA) + 
  scale_x_date(limits=c(as.Date("2004-01-01"), as.Date("2005-06-30")), date_breaks = "1 month", date_labels = "%b-%y", expand = c(0,0)) + 
  scale_y_continuous(limits=c(0,0.6), breaks=seq(0.0, 0.7, 0.1), expand = c(0,0)) + 
  geom_errorbar(aes(ymin=LowerCI, ymax=UpperCI), width=.1, position=pd, na.rm=TRUE) + 
  theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 5, color="black", face="bold"), legend.position = "none",
        panel.background = element_blank(), panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(), axis.title.x=element_blank(),
        axis.ticks.y=element_blank(), axis.text.y=element_blank(), axis.title.y=element_blank())

cowplot::plot_grid(trendlineGraph, trendlineGraph2)



